<template>
  <div :id="id" :class="className" :style="{ height: height, width: width }"></div>
</template>

<script>
import tdTheme from './theme.json' // 引入默认主题
// import resizeMixins from "@/utils/resizeMixins";
// import '../map/fujian.js'

export default {
  name: 'Echart',
  // mixins: [resizeMixins],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    id: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '1000px'
    },
    height: {
      type: String,
      default: '220px'
    },
    options: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      chartstau: true,
      chart: null
    }
  },
  watch: {
    options: {
      handler (options) {
        // 设置true清空echart缓存
        this.chart.setOption(options, true)
      },
      deep: true
    }
    // ,height: {
    //   handler(e) {
    //     this.chartstau = false
    //     this.chartstau = true
    //     this.height = e
    //     this.$nextTick(
    //       () => {
    //         this.chartstau = true
    //       }
    //     )
    //   },
    //   deep: true
    // }
  },
  mounted () {
    this.$echarts.registerTheme('tdTheme', tdTheme); // 覆盖默认主题
    this.initChart();
  },
  methods: {
    initChart () {
      // 初始化echart
      this.chart = this.$echarts.init(this.$el, 'tdTheme')
      this.chart.setOption(this.options, true)
    }
  }
}
</script>

<style>
</style>
